package com.kaiyiweitong.tongxing.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridLayout;

import com.kaiyiweitong.tongxing.R;
import com.kaiyiweitong.tongxing.activity.MainActivity;
import com.kaiyiweitong.tongxing.activity.classify.ServiceInfoActivity;
import com.kaiyiweitong.tongxing.adapter.ClassifyItemAdapter;
import com.kaiyiweitong.tongxing.base.ClassifyHorAdapter;
import com.kaiyiweitong.tongxing.base.ClassifyVerAdapter;
import com.kaiyiweitong.tongxing.other.SpaceItemDecoration;
import com.kaiyiweitong.tongxing.util.CommonUtil;

import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * Created by Administrator on 2017/12/15 0015.
 */

public class ClassifyFragment extends Fragment {
    @Bind(R.id.rv_classify_hor)
    RecyclerView mRvClassifyHor;
    @Bind(R.id.rv_classify_second)
    RecyclerView mRvClassifySecond;
    @Bind(R.id.rv_classify_third)
    RecyclerView mRvClassifyThird;
    @Bind(R.id.rv_classify_item)
    RecyclerView mRvClassifyItem;
    private View mView;
    private MainActivity mActivity;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_classify, null);
        mActivity = (MainActivity) getActivity();
        ButterKnife.bind(this, mView);
        init();
        return mView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    private void init() {
        mRvClassifyHor.setLayoutManager(new GridLayoutManager(mActivity, 1, GridLayout.HORIZONTAL, false));
        ClassifyHorAdapter classifyHorAdapter = new ClassifyHorAdapter(mActivity);
        mRvClassifyHor.setAdapter(classifyHorAdapter);

        mRvClassifySecond.setLayoutManager(new GridLayoutManager(mActivity, 1, GridLayout.VERTICAL, false));
        ClassifyVerAdapter classifySecondAdapter = new ClassifyVerAdapter(mActivity, mVerListener);
        mRvClassifySecond.setAdapter(classifySecondAdapter);

        mRvClassifyThird.setLayoutManager(new GridLayoutManager(mActivity, 1, GridLayout.VERTICAL, false));
        ClassifyVerAdapter classifyThirdAdapter = new ClassifyVerAdapter(mActivity, mVerListener);
        mRvClassifyThird.setAdapter(classifyThirdAdapter);

        mRvClassifyItem.setLayoutManager(new GridLayoutManager(mActivity, 1, GridLayout.VERTICAL, false));
        ClassifyItemAdapter classifyItemAdapter = new ClassifyItemAdapter(mActivity, mItemListener);
        mRvClassifyItem.addItemDecoration(new SpaceItemDecoration(CommonUtil.dip2px(mActivity, 20), 1));
        mRvClassifyItem.setAdapter(classifyItemAdapter);
    }

    private ClassifyItemAdapter.OnClickListener mItemListener = new ClassifyItemAdapter.OnClickListener() {
        @Override
        public void onClick(int position) {
            Intent intent = new Intent(mActivity, ServiceInfoActivity.class);

            startActivity(intent);
        }
    };


    private ClassifyVerAdapter.OnClickListener mVerListener = new ClassifyVerAdapter.OnClickListener() {
        @Override
        public void onClick(int position) {

        }
    };
}
